﻿#ifndef USERRELATION_H
#define USERRELATION_H

#include <QObject>
#include <QSqlQuery>
#include <QJsonObject>

class UserRelation : public QObject
{
    Q_OBJECT
public:

    enum RelationType{
        Client=1,
        Giver=2,
    };

    Q_ENUM(RelationType)

    explicit UserRelation(QObject *parent = nullptr);

    int id;
    QString sourceUsername;
    QString sourceCompanyId;
    QString targetUsername;
    QString targetCompanyId;
    QString nickName;           //对方公司名称
    QString nickNamePinyin;     //对方公司名称拼音
    QString contact;            //对方用户姓名
    QString contactPinyin;      //对方用户姓名拼音
    QString tel;                //对应用户电话
    int type;
    int isPlatform;
    double ticketIn;
    double ticketOut;
    double moneyIn;
    double moneyOut;
    double preTicketIn;
    double preTicketOut;
    double preMoneyIn;
    double preMoneyOut;
    int hasSubAccount;
    int hasTicketHistory;
    int credit;
    QString remark;
    QString primaryDirectory;
    QString secondaryDirectory;

    void loadFromJsonObject(QJsonObject obj);

    void loadFromSqlQuery(QSqlQuery query);

    QString toJson();

    static QString toJson(QList<UserRelation*> relations){
        QString jsonStr = "[";

        for(UserRelation *relation:relations){
            jsonStr.append(relation->toJson()+",");
        }

        jsonStr.append("]");

        return jsonStr;
    }
signals:

public slots:
};

#endif // USERRELATION_H
